#include "StdAfx.h"
#include <gtest/gtest.h>

#include <vector>
#include <dbghelp.h>
#include <shellapi.h>
#include <time.h>
#include <utility/utility.h>
#include <iostream>
using namespace std;
using namespace sysinfo::windows;

#if 0

void PrintAllValue(RegKey& key)
{
	int i = 0, j = 0;
	DWORD type;
	string name, cls, value;
	while (key.EnumValue(i++, name, type, value))
	{
		switch (type)
		{
		case REG_SZ:
			printf("REG_SZ: %s\n", value.c_str());
			break;
		case REG_DWORD:
			printf("REG_DWORD: %u\n", RegKey::ToDWORD(value));
			break;
		}
	}
	while (key.EnumKey(j++, name, cls))
		PrintAllValue(key.GetKey(name));
}

TEST(utility, reg)
{
#define KEY_NAME "SOFTWARE\\utility_reg"
	RegKey reg(HKEY_LOCAL_MACHINE);
	reg.RemoveKey(KEY_NAME);
	if (!reg.HasKey(KEY_NAME))
	{
		RegKey reg2 = reg.PutKey(KEY_NAME);
		RegKey sub = reg2.PutKey("subkey");
		if (!sub.PutValue("value_string", REG_SZ, "string1")) printf("error put value1\n");
		if (!sub.PutValue("value_dword", REG_DWORD, RegKey::FromDWORD(123))) printf("error put value2\n");
		if (!sub.PutValue("value_binary", REG_BINARY, string("\0\1\2", 3))) printf("error put value3\n");

		if (!reg2.PutValue("value_string", REG_SZ, "string1")) printf("error put value11\n");
		if (!reg2.PutValue("value_dword", REG_DWORD, RegKey::FromDWORD(123))) printf("error put value12\n");
		if (!reg2.PutValue("value_binary", REG_BINARY, string("\0\1\2", 3))) printf("error put value13\n");
	}
	PrintAllValue(reg.GetKey(KEY_NAME));
}

#endif